import request from "@/utils/request";

const BASE_URL = "/admin";

const setAPI = {
  refreshAll() {
    return request<any, PageResult<PageVO[]>>({
      url: `${BASE_URL}/common/setting/refreshAll`,
      method: "POST",
    });
  },
  /** 获取通知轮播分页数据 */
  getPage(data?: SetPageQuery) {
    return request<any, PageResult<PageVO[]>>({
      url: `${BASE_URL}/common/setting/pageList`,
      method: "POST",
      data,
    });
  },

  /**
   * 批量删除
   *
   * @param ids IDs数组
   */
  deleteByIds(data: any) {
    return request({
      url: `${BASE_URL}/common/setting/del`,
      method: "post",
      data,
    });
  },

  /**
   * 更新
   *
   * @param id ID
   * @param data 轮播组表单数据
   */
  update(data: configForm) {
    return request({
      url: `${BASE_URL}/common/setting/update`,
      method: "post",
      data,
    });
  },

  /**
   * 轮播组
   *
   * @param data 轮播组表单数据
   * @returns
   */
  add(data: configForm) {
    return request({
      url: `${BASE_URL}/common/setting/add`,
      method: "post",
      data,
    });
  },
};

export default setAPI;

/** 分页查询参数 */
export interface SetPageQuery extends PageQuery {
  /** 标题 */
  s_name?: string;
  /** code */
  s_code?: string;
}

/** 分页对象 */
export interface PageVO {
  id: string;
  /** name */
  name?: string;
  /** code */
  code?: string;
  /** 备注 */
  remark?: string;
}

/**
 * 表单对象
 */
export interface configForm {
  id: string | number;
  // 唯一标识
  code: string;
  // 排序
  name: string;
  // 对应input的type
  input_type: string;
  // 值
  val: string;
  // 选择范围等
  ext: any;
  // 选择范围等(页面显示)
  extJson: any;
  // pid
  pid: number;
  // 排序
  sort: number;
  // 备注
  remark: string;
  // 多选选中
  checkbox: any;
}
